/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package editor.impl;

import editor.Editor;
import editor.EditorPackage;
import editor.Node;
import editor.Relationship;
import editor.Root;
import editor.RootRelationship;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Editor</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link editor.impl.EditorImpl#getNodes <em>Nodes</em>}</li>
 *   <li>{@link editor.impl.EditorImpl#getRelationships <em>Relationships</em>}</li>
 *   <li>{@link editor.impl.EditorImpl#getRoot <em>Root</em>}</li>
 *   <li>{@link editor.impl.EditorImpl#getRootRelationship <em>Root Relationship</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EditorImpl extends EObjectImpl implements Editor {
	/**
   * The cached value of the '{@link #getNodes() <em>Nodes</em>}' containment reference list.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getNodes()
   * @generated
   * @ordered
   */
	protected EList<Node> nodes;

	/**
   * The cached value of the '{@link #getRelationships() <em>Relationships</em>}' containment reference list.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getRelationships()
   * @generated
   * @ordered
   */
	protected EList<Relationship> relationships;

	/**
   * The cached value of the '{@link #getRoot() <em>Root</em>}' containment reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getRoot()
   * @generated
   * @ordered
   */
	protected Root root;

	/**
   * The cached value of the '{@link #getRootRelationship() <em>Root Relationship</em>}' containment reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getRootRelationship()
   * @generated
   * @ordered
   */
	protected RootRelationship rootRelationship;

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	protected EditorImpl() {
    super();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	protected EClass eStaticClass() {
    return EditorPackage.Literals.EDITOR;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public EList<Node> getNodes() {
    if (nodes == null)
    {
      nodes = new EObjectContainmentEList<Node>(Node.class, this, EditorPackage.EDITOR__NODES);
    }
    return nodes;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public EList<Relationship> getRelationships() {
    if (relationships == null)
    {
      relationships = new EObjectContainmentEList<Relationship>(Relationship.class, this, EditorPackage.EDITOR__RELATIONSHIPS);
    }
    return relationships;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Root getRoot() {
    return root;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetRoot(Root newRoot, NotificationChain msgs) {
    Root oldRoot = root;
    root = newRoot;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EditorPackage.EDITOR__ROOT, oldRoot, newRoot);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setRoot(Root newRoot) {
    if (newRoot != root)
    {
      NotificationChain msgs = null;
      if (root != null)
        msgs = ((InternalEObject)root).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - EditorPackage.EDITOR__ROOT, null, msgs);
      if (newRoot != null)
        msgs = ((InternalEObject)newRoot).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - EditorPackage.EDITOR__ROOT, null, msgs);
      msgs = basicSetRoot(newRoot, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.EDITOR__ROOT, newRoot, newRoot));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public RootRelationship getRootRelationship() {
    return rootRelationship;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetRootRelationship(RootRelationship newRootRelationship, NotificationChain msgs) {
    RootRelationship oldRootRelationship = rootRelationship;
    rootRelationship = newRootRelationship;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EditorPackage.EDITOR__ROOT_RELATIONSHIP, oldRootRelationship, newRootRelationship);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setRootRelationship(RootRelationship newRootRelationship) {
    if (newRootRelationship != rootRelationship)
    {
      NotificationChain msgs = null;
      if (rootRelationship != null)
        msgs = ((InternalEObject)rootRelationship).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - EditorPackage.EDITOR__ROOT_RELATIONSHIP, null, msgs);
      if (newRootRelationship != null)
        msgs = ((InternalEObject)newRootRelationship).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - EditorPackage.EDITOR__ROOT_RELATIONSHIP, null, msgs);
      msgs = basicSetRootRelationship(newRootRelationship, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.EDITOR__ROOT_RELATIONSHIP, newRootRelationship, newRootRelationship));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.EDITOR__NODES:
        return ((InternalEList<?>)getNodes()).basicRemove(otherEnd, msgs);
      case EditorPackage.EDITOR__RELATIONSHIPS:
        return ((InternalEList<?>)getRelationships()).basicRemove(otherEnd, msgs);
      case EditorPackage.EDITOR__ROOT:
        return basicSetRoot(null, msgs);
      case EditorPackage.EDITOR__ROOT_RELATIONSHIP:
        return basicSetRootRelationship(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID)
    {
      case EditorPackage.EDITOR__NODES:
        return getNodes();
      case EditorPackage.EDITOR__RELATIONSHIPS:
        return getRelationships();
      case EditorPackage.EDITOR__ROOT:
        return getRoot();
      case EditorPackage.EDITOR__ROOT_RELATIONSHIP:
        return getRootRelationship();
    }
    return super.eGet(featureID, resolve, coreType);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
    switch (featureID)
    {
      case EditorPackage.EDITOR__NODES:
        getNodes().clear();
        getNodes().addAll((Collection<? extends Node>)newValue);
        return;
      case EditorPackage.EDITOR__RELATIONSHIPS:
        getRelationships().clear();
        getRelationships().addAll((Collection<? extends Relationship>)newValue);
        return;
      case EditorPackage.EDITOR__ROOT:
        setRoot((Root)newValue);
        return;
      case EditorPackage.EDITOR__ROOT_RELATIONSHIP:
        setRootRelationship((RootRelationship)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eUnset(int featureID) {
    switch (featureID)
    {
      case EditorPackage.EDITOR__NODES:
        getNodes().clear();
        return;
      case EditorPackage.EDITOR__RELATIONSHIPS:
        getRelationships().clear();
        return;
      case EditorPackage.EDITOR__ROOT:
        setRoot((Root)null);
        return;
      case EditorPackage.EDITOR__ROOT_RELATIONSHIP:
        setRootRelationship((RootRelationship)null);
        return;
    }
    super.eUnset(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public boolean eIsSet(int featureID) {
    switch (featureID)
    {
      case EditorPackage.EDITOR__NODES:
        return nodes != null && !nodes.isEmpty();
      case EditorPackage.EDITOR__RELATIONSHIPS:
        return relationships != null && !relationships.isEmpty();
      case EditorPackage.EDITOR__ROOT:
        return root != null;
      case EditorPackage.EDITOR__ROOT_RELATIONSHIP:
        return rootRelationship != null;
    }
    return super.eIsSet(featureID);
  }

} //EditorImpl
